package com.roads.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName RegexUtils
 * @Description 正则表达式工具类
 * @Author nhp
 * @Date 2022/10/30 0008 13:22
 **/
public class RegexUtils {

    /**
     * 电话正则表达式
     */
    public static final String PHONE_PATTERN = "0\\d{2,3}[-]?\\d{7,8}|0\\d{2,3}\\s?\\d{7,8}|^[1][3,4,5,6,7,8,9][0-9]{9}$";

    /**
     * 电子邮件正在表达式
     */
    public static final String EMAIL_PATTERN = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";

    /**
     * 验证是否是联系电话
     *
     * @param phone 电话号码
     * @return 结果
     */
    public static boolean isPhone(String phone) {
        Pattern pattern = Pattern.compile(PHONE_PATTERN);
        Matcher matcher = pattern.matcher(phone);
        boolean result = matcher.matches();
        return result;
    }

    /**
     * 验证是否是电子邮件
     *
     * @param email 电子邮件
     * @return 结果
     */
    public static boolean isEmail(String email) {
        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher = pattern.matcher(email);
        boolean result = matcher.matches();
        return result;
    }

    public static void main(String[] args) {
        String email = "382934377@163.com";
        System.out.println(isEmail(email));
    }

}
